package cn.znzz.cjm.pay.service.impl;


import cn.znzz.cjm.basic.exception.BusinessException;
import cn.znzz.cjm.basic.service.impl.BaseServiceImpl;
import cn.znzz.cjm.pay.domain.AlipayInfo;
import cn.znzz.cjm.pay.domain.PayBill;
import cn.znzz.cjm.pay.mapper.AlipayInfoMapper;
import cn.znzz.cjm.pay.mapper.PayBillMapper;
import cn.znzz.cjm.pay.service.IPayBillService;
import cn.znzz.cjm.pay.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Autowired
    private AlipayInfoMapper alipayInfoMapper;

    @Autowired
    private PayBillMapper payBillMapper;

    @Override
    public String pay(PayBill bill) {
        if(bill==null){
            throw new BusinessException("使劲骂！！");
        }
        PayBill payBill = payBillMapper.loadById(bill.getId());
        if(payBill==null){
            throw new BusinessException("使劲骂！！");
        }
        //是否是支付宝
        switch (bill.getPayChannel().intValue()){
            case 1:{
                AlipayInfo info = alipayInfoMapper.loadByShopId(bill.getShop_id());
                return AlipayUtils.pay(info, payBill);
            }
            default:break;
        }
       return null;
    }

    @Override
    public PayBill loadByUnionPaySn(String unionPaySn) {
        return payBillMapper.loadByUnionPaySn(unionPaySn);
    }
}
